<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <%@ include file="/WEB-INF/views/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Insert title here</title>
  <script type="text/javascript">
	var datagrid;
	var rowEditor=undefined;
	$(function(){
		datagrid=$("#dg").datagrid({
			url:"${cs}/cs/credit/list",//加载的URL
		    isField:"id",
			pagination:true,//显示分页
			pageSize:10,//分页大小
			pageList:[10,15,20],//每页的个数
			fit:true,//自动补全
			fitColumns:true,
			iconCls:"icon-save",//图标
			columns:[[      //每个列具体内容
		              {field:'id', hidden:true },   
		              {field:'nick', title:'认证人',  width:"10%", align:'center' },
		              {field:'email',title:'邮箱',width:"15%", align:'center'},
		              {field:'phone',title:'手机',width:"15%", align:'center'},
		              {field:'materialurl',title:'认证资料（点击查看大图）',width:"30%", align:'center',
		             	 formatter:function(value,rowData,rowIndex) { 
		             	 	return '<a href="${cs}'+value+'" target="_blank"><img  alt="认证材料"   id="imghead"  border=0  src="${cs}'+value+'" width="100px" height="75px"/></a>';
		             	 }
		              },
		              {field:'msg',title:'认证信息',width:"20%", align:'center'},
		              {field:'state',title:'状态',width:"11%", align:'center',
			             	 formatter:function(value,rowData,rowIndex) { 
			             	 	if(value==0){
			             	 		return "<span style='color:#3399FF'>待批准</span>";
			             	 	}else if(value==1){
			             	 		return "<span style='color:green'>认证通过</span>";
			             	 	}else{
			             	 		return "<span style='color:red'>不通过</span>";
			             	 	}
			             	 }
			              }
		          ]],
			toolbar:[              //工具条
			        {text:"打回",iconCls:"icon-redo",handler:function(){//回调函数
			        	var rows=datagrid.datagrid('getSelections');
			        	if(rows.length!=1){
			        		$.messager.alert('警告','一次只能操作一条数据','error');
			        	}else{
			        		var rows = datagrid.datagrid('getSelections');
			        		if(rows[0].state == 1){
        						$.messager.alert('错误', "请勿重复操作已通过的信息！", 'error');
			        			return;
        					}
		        			var reason=prompt("请输入打回理由：","");
		        			if(reason!=null){
			        			if(reason!=""){
			        				var rows = datagrid.datagrid('getSelections');
			        				$.ajax({
			        					url : '${cs}/cs/credit/save',
			        					data : 'state=2&id='+rows[0].id+'&msg='+reason,
			        					method: 'POST',
			        					type:'json',
			        					dataType : 'json',
			        					success : function(r) {
			        						if (r>0) {
			        							$.messager.show({
			        								msg : "操作成功",
			        								title : '成功'
			        							});
			        							datagrid.datagrid('reload');
			        						} else {
			        							$.messager.alert('错误',"操作失败", 'error');
			        						}
			        						datagrid.datagrid('unselectAll');
			        					}
			        				});
			        			}else{
			        				$.messager.alert('警告','输入有误！','error');
			        			}
			        		}
			        	}
			        }},
			        {text:"审核通过",iconCls:"icon-filter",handler:function(){//回调函数
			        	var rows=datagrid.datagrid('getSelections');
			        	if(rows.length!=1){
			        		$.messager.alert('警告','一次只能操作一条数据','error');
			        	}else{
			        		var rows = datagrid.datagrid('getSelections');
			        		if(rows[0].state == 1){
        						$.messager.alert('错误', "请勿重复操作已通过的信息！", 'error');
			        			return;
        					}
			        		$.messager.confirm('确定','您确定要通过吗',function(t){
			        			if(t){
			        				var rows = datagrid.datagrid('getSelections');
			        				$.ajax({
			        					url : '${cs}/cs/credit/pass',
			        					data : 'state=1&id='+rows[0].id+'&userid='+rows[0].userid,
			        					method: 'POST',
			        					type:'json',
			        					dataType : 'json',
			        					success : function(r) {
			        						if (r>0) {
			        							$.messager.show({
			        								msg : "操作成功，已为您进行开户操作，请重新登录！",
			        								title : '成功'
			        							});
			        							datagrid.datagrid('reload');
			        						} else {
			        							$.messager.alert('错误',"操作失败", 'error');
			        						}
			        						datagrid.datagrid('unselectAll');
			        					}
			        				});
			        			
			        			}
			        		})
			        	}
			        }
			      }  
			  ]
		});
		$('#reRole').dialog({
            title: "角色修改",
            closed:true,
            modal: true, //dialog继承自window，而window里面有modal属性，所以dialog也可以使用
            toolbar: [{
					text:'Ok',
				iconCls:'icon-ok',
				handler:function(){
					$('#ff2').form('submit',{
						onSubmit:function(){
							var isValid = $(this).form('validate');
							return isValid;
						},
						success: function(r){
							if(r>0){
								$.messager.show({
									title:"Success！",
									msg:"恭喜您，操作成功！"
								})
								$('#reRole').dialog('close');
							}else{
								$.messager.alert('错误',"数据出错！", 'error');
							}
						}
					},"json");
				
				}
			},{
				text:'Cancel',
				iconCls:'icon-Cancel',
				handler:function(){
					$('#reRole').dialog('close');
					$('#ff2').form('clear');
				}
			}],
			onClose: function() {
				$('#ff2').form('clear');
				datagrid.datagrid('unselectAll');
				datagrid.datagrid('reload');
			}
        });
		$('#infEdit').dialog({
            title: "角色信息修改",
            closed:true,
            modal: true, //dialog继承自window，而window里面有modal属性，所以dialog也可以使用
            toolbar: [{
					text:'Ok',
				iconCls:'icon-ok',
				handler:function(){
					$('#ff3').form('submit',{
						onSubmit:function(){
							var isValid = $(this).form('validate');
							return isValid;
						},
						success: function(r){
							if(r>0){
								$.messager.show({
									title:"Success！",
									msg:"恭喜您，操作成功！"
								})
								$('#infEdit').dialog('close');
							}else{
								$.messager.alert('错误',"数据出错！", 'error');
							}
						}
					},"json");
				
				}
			},{
				text:'Cancel',
				iconCls:'icon-Cancel',
				handler:function(){
					$('#infEdit').dialog('close');
					$('#ff3').form('clear');
				}
			}],
			onClose: function() {
				$('#ff2').form('clear');
				datagrid.datagrid('unselectAll');
				datagrid.datagrid('reload');
			}
        });
		 $('#dd').dialog({
             title: "新增用户",
             closed:true,
             modal: true, //dialog继承自window，而window里面有modal属性，所以dialog也可以使用
             toolbar: [{
					text:'Ok',
				iconCls:'icon-ok',
				handler:function(){
					$('#ff').form('submit',{
						onSubmit:function(){
							var isValid = $(this).form('validate');
							return isValid;
						},
						success: function(){
							$.messager.show({
								title:"Success！",
								msg:"恭喜您，操作成功！"
							})
							$('#ff').form('clear');
						}
					},"json");
				
				}
			},{
				text:'Cancel',
				handler:function(){
					$('#dd').dialog('close');
				}
			}],
			onClose: function() {
				$('#ff').form('clear');
				datagrid.datagrid('reload');
			}
         });
		 
		 initCombox();
	    
		$("#btn_search").click(function(){
			var param = $("#searchForm").serializeJson();
			datagrid.datagrid('load', param);

			});
		});
	
	function initCombox() {
		$('#state').combobox({
			 valueField:'id',
			 textField:'name',
			 data:[{"id":"-1","name":"全部"},{"id":"0","name":"待审核"},{"id":"1","name":"已通过"},{"id":"2","name":"不通过"}]
			 })
	}
     var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}   
     function isCardID(sId){   
         var iSum=0 ;  
         var info="" ;  
         if(!/^\d{17}(\d|x)$/i.test(sId)) return "你输入的身份证长度或格式错误";   
         sId=sId.replace(/x$/i,"a");   
         if(aCity[parseInt(sId.substr(0,2))]==null) return "你的身份证地区非法";   
         sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));   
         var d=new Date(sBirthday.replace(/-/g,"/")) ;  
         if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "身份证上的出生日期非法";   
         for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) ;  
         if(iSum%11!=1) return "你输入的身份证号非法";   
         return true;//aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")   
     }
     $.extend($.fn.validatebox.defaults.rules, {     
     	    idcared: {     
     	        validator: function(value,param){    
     	            var flag= isCardID(value);  
     	            return flag==true?true:false;    
     	        },     
     	        message: '不是有效的身份证号码'    
     	    },
	     username: {     
		        validator: function(value,param){    
		        	var flag=false;
		        	$.ajax({
		        		type:"post",
		        		url:"${cs}/exitsUsername",
		        		data:"username="+value,
		        		dataType:"json",
		        		async : false,
		        		success:function(result){
    	    				flag=result;
    	    			}
		        	})
		        	return flag==true?true:false; 
		        },     
		        message: '账户信息已存在！'    
		    },
		    phone:{     
		        validator: function(value,param){
		        	var flag=/^1[3|4|5|8][0-9]\d{4,8}$/.test(value);
		        	return flag==true?true:false; 
		        },     
		        message: '手机号不合法!'    
		    },
		    equalTo: { validator: function (value, param) { return $(param[0]).val() == value; }, message: '两次输入密码不一致！' }
     	}); 
    </script>
</head>
<body style="padding:0 4px; margin:0;  overflow: hidden; ">
<div class="easyui-layout" style="width:100%;height:100%;" data-options="fit:true">
		<div title="信贷认证审核" data-options="region:'north'" style="height:70px">
		 <form id="searchForm" >
			<table cellpadding="5">
				    		<tr>
				    			<td>姓名:</td>
				    			<td><input class="easyui-textbox" type="text" id="username"  name="userinf.nick" ></input></td>
				    			<td>状态:</td>
				    			<td><input class="easyui-combobox" type="text" data-options="panelHeight:'auto',value:'-1'" id="state"  name="state" ></input></td>
				    			<td ><a href="#" id="btn_search" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px">Search</a></td>
				    		</tr>
				    		<tr>
				    		</tr>
				    	</table>
				  </form>
		</div>
				<div data-options="region:'center'" >
					<table id="dg" >
					</table>
				</div>
		</div>
</body>
</html>